package com.fosss.band.controller;

import com.fosss.band.entity.Song;
import com.fosss.band.service.SongService;
import com.fosss.band.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: fosss
 * Date: 2024/1/6
 * Time: 19:44
 * Description:
 */
@Api(tags = "歌曲相关接口")
@RestController
@RequestMapping("/song")
@Slf4j
public class SongController {

    @Resource
    private SongService songService;

    @ApiOperation("根据专辑id查询歌曲")
    @GetMapping("/selectByAlbumId/{userId}/{id}")
    public Result selectByAlbumId(@PathVariable("userId") Integer userId, @PathVariable("id") Integer id) {
        log.info("根据专辑id查询歌曲:{}", id);
        return songService.selectByAlbumId(userId, id);
    }

    @ApiOperation("添加歌曲")
    @PostMapping("/add")
    public Result add(@RequestBody Song song) {
        log.info("添加歌曲:{}", song);
        return songService.add(song);
    }

    @ApiOperation("删除歌曲")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        log.info("删除歌曲:{}", id);
        return songService.deleteById(id);
    }

    @ApiOperation("根据id查询歌曲")
    @GetMapping("/getSongById/{id}")
    public Result getById(@PathVariable("id") Integer id) {
        log.info("查询歌曲：{}", id);
        return songService.getById(id);
    }

    @ApiOperation("修改歌曲")
    @PutMapping("/update")
    public Result update(@RequestBody Song song) {
        log.info("修改歌曲：{}", song);
        return songService.update(song);
    }
}
















